﻿String.prototype.Format = function Format()
{
	var res = "", lastIndex = 0;
	var rgx = new RegExp("\\{(?!\\{)(\\d+)(?::([^}]*))?\\}(?!\\})");
	var mcl = rgx.Matches(this);
	for (var i = 0; i < mcl.length; ++i)
	{
		var 
			m = mcl[i]
			, argIndex = parseInt(m[1])
			, value = arguments[argIndex]
			, format = m[2]
			, strValue = format == null ? value.toString() : value.toString(format);
		res += this.substr(lastIndex, m.index - lastIndex);
		res += strValue;
		lastIndex += m[0].length;
	}
	res += this.substr(lastIndex, this.length - lastIndex);
	return res;
}
